package com.heima.article.feign;

import com.alibaba.fastjson.JSON;
import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ApArticleService;
import com.heima.article.service.ArticleFreemarkerService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Slf4j
public class ArticleClient implements IArticleClient {

    @Autowired
    private ApArticleService apArticleService;
    @Autowired
    private ArticleFreemarkerService articleFreemarkerService;

    @Override
    @PostMapping("/api/v1/article/url")
    public ResponseResult createStaticURL(Map<String, Object> map) {
        if(map != null){
            String articleId = (String) map.get("articleId");
            log.info("静态文件生成-接收的文章id:{}",articleId);
            articleFreemarkerService.buildArticleToMinIO(Long.valueOf(articleId));
            return ResponseResult.okResult(null);
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
    }

    @PostMapping("/api/v1/article/save")
    @Override
    public ResponseResult saveAppArticle(ArticleDto dto) {
        return apArticleService.saveAppArticle(dto);
    }
}
